export function tansParams(params) {
  if (params === undefined) return
  let res = ''
  Object.keys(params).forEach((e) => {
    res += `${e}=${params[e]}&`
  })
  res += 't=' + new Date().getTime()
  return res
}
// 函数方式
// 函数方式
export class PriorityQueue {
  constructor() {
    this.items = []
    //封装一个新的构造函数，用于保存元素和元素的优先级
    class QueueElement {
      constructor(element, priority) {
        this.element = element
        this.priority = priority
      }
    }
    //1.实现插入方法
    newFunction().enqueue = function (element, priority) {
      //1.创建queueElement对象
      var queueElement = new QueueElement(element, priority)
      //2.判断队列是否为空
      if (this.items.length == 0) {
        this.items.push(queueElement)
      } else {
        var flag = false
        for (var i = 0; i < this.items.length; i++) {
          if (queueElement.priority > this.items[i].priority) {
            this.items.splice(i, 0, queueElement)
            flag = true
            break
          }
        }
        if (!flag) {
          this.items.push(queueElement)
        }
      }
    }

    // newFunction().pushArray = function (array) {
    //   array.map(e => {
    //     return new QueueElement(e, new Date(e.timeStamp).getTime())
    //   })
    //   var queueElement = new QueueElement(element, priority)
    //   if (this.items.length == 0) {
    //     this.items.push(queueElement)
    //   } else {
    //     var flag = false
    //     for (var i = 0; i < this.items.length; i++) {
    //       if (queueElement.priority > this.items[i].priority) {
    //         this.items.splice(i, 0, queueElement)
    //         flag = true
    //         break
    //       }
    //     }
    //     if (!flag) {
    //       this.items.push(queueElement)
    //     }
    //   }
    // }

    newFunction().clear = function () {
      this.items.length = 0
    }

    newFunction().size = function () {
      return this.items.length
    }

    function newFunction() {
      return PriorityQueue.prototype
    }
  }
}
